package com.mzq.langchain4j_springboot.web.service.Impl;

import com.mzq.langchain4j_springboot.web.entity.BusinessInspection;
import com.mzq.langchain4j_springboot.web.mapper.BusinessInspectionMapper;
import com.mzq.langchain4j_springboot.web.service.BusinessInspectionService;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import jakarta.annotation.Resource;
import org.mybatis.logging.Logger;
import org.mybatis.logging.LoggerFactory;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class BusinessInspectionServiceImpl implements BusinessInspectionService {

    private static final Logger log = LoggerFactory.getLogger(HouseInfoServiceImpl.class);

    @Resource
    private BusinessInspectionMapper businessInspectionMapper;

    @Override
    public int insertBusinessInspection(BusinessInspection businessInspection) {
        return businessInspectionMapper.insertBusinessInspection(businessInspection);
    }

    @Override
    public int updateBusinessInspection(BusinessInspection businessInspection) {
        return businessInspectionMapper.updateBusinessInspection(businessInspection);
    }

    @Tool("根据商业检查ID查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionById(
            @P("商业检查ID") String id
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setId(id);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据工单号查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByWorkOrder(
            @P("工单号") String workOrder
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setWorkOrder(workOrder);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据房产编号查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByPropertyNum(
            @P("房产编号") String propertyNum
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setPropertyNum(propertyNum);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据巡检状态查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByMaintenanceStatus(
            @P("巡检状态") String maintenanceStatus
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setMaintenanceStatus(maintenanceStatus);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据工单状态查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByOrderStatus(
            @P("工单状态") String orderStatus
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setOrderStatus(orderStatus);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据负责单位查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByDeptId(
            @P("负责单位") String deptId
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setDeptId(deptId);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据负责人_维修人查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByHeadId(
            @P("负责人_维修人") String headId
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setHeadId(headId);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据创建时间查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByCreateTime(
            @P("创建时间") String createTime
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setCreateTime(createTime);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据创建人查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByCreateBy(
            @P("创建人") String createBy
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setCreateBy(createBy);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据工单完成时间查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByFinishTime(
            @P("工单完成时间") String finishTime
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setFinishTime(finishTime);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据审批状态查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByApprovalStatus(
            @P("审批状态") String approvalStatus
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setApprovalStatus(approvalStatus);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据工单类型查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByWorkType(
            @P("工单类型") String workType
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setWorkType(workType);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据备注查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByRemark(
            @P("备注") String remark
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setRemark(remark);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据维修项目查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByMaintenanceItems(
            @P("维修项目") String maintenanceItems
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setMaintenanceItems(maintenanceItems);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据检查项目表关联字段查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByInspectionCode(
            @P("检查项目表关联字段") String inspectionCode
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setInspectionCode(inspectionCode);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据工单计划完成时间查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByPlannedFinishTime(
            @P("工单计划完成时间") String plannedFinishTime
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setPlannedFinishTime(plannedFinishTime);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据所属模块功能类型查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByModuleType(
            @P("所属模块功能类型") String moduleType
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setModuleType(moduleType);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据巡检工单名称查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByWorkName(
            @P("巡检工单名称") String workName
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setWorkName(workName);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }

    @Tool("根据是否有安全隐患查询商业检查信息")
    public List<Map<String, Object>> getBusinessInspectionByDangerYes(
            @P("是否有安全隐患") String dangerYes
    ) {
        BusinessInspection bi = new BusinessInspection();
        bi.setDangerYes(dangerYes);
        return businessInspectionMapper.selectBusinessInspectionList(bi);
    }
}
